#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+1;
int T,n,a[N],c[N],ans1;
int dfs(int x,int co,int ans)
{
	c[x]=co;
	if(x==n) return ans;
	for(int i=x-1;i>=0;i--)
	{
		if(c[i]==co && a[i]==a[x]) {ans+=a[x];break;}
	}
	return max(dfs(x+1,1,ans),dfs(x+1,0,ans));
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	for(int k=1;k<=T;k++)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		ans1=max(dfs(0,0,0),dfs(0,1,0));
		cout<<ans1<<endl;
	}
}
